package com.skeleton.server.blog.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.skeleton.common.base.dto.ResultDto;
import com.skeleton.common.base.service.impl.BaseServiceImpl;
import com.skeleton.db.dao.IBlogCommentDao;
import com.skeleton.db.dto.BlogCommentDto;
import com.skeleton.db.entity.BlogComment;
import com.skeleton.server.blog.service.IBlogCommentService;

@Service
public class BlogCommentServiceImpl extends BaseServiceImpl implements IBlogCommentService {

	@Resource
	private IBlogCommentDao iBlogCommentDao;

	@Override
	public ResultDto doAddBlogComment(BlogCommentDto bcDto) {
		logger.debug("-------BlogCommentServiceImpl---doAddBlogComment-----------------");
		ResultDto rd = new ResultDto();

		BlogComment bcEntity = bcDto.toEntity();

		iBlogCommentDao.insert(bcEntity);

		rd.setSuccess(true);
		return rd;
	}

	@Override
	public ResultDto getBlogCommentByArticleId(BlogCommentDto bcDto) {
		logger.debug("-------BlogCommentServiceImpl---getBlogCommentByArticleId-----------------");
		ResultDto rd = new ResultDto();

		BlogComment bcEntity = bcDto.toEntity();

		List<BlogComment> bcList = iBlogCommentDao.selectCommentByArticleId(bcEntity);
		for (int i = 0; i < bcList.size(); i++) {
			BlogComment bc = bcList.get(i);
			BlogCommentDto bcd = bc.toDto();
			rd.addToDtoMap("BlogCommentDtoList", bcd);
		}

		rd.setSuccess(true);
		return rd;
	}

}
